<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>R字母计数器</title>
    <style>
        body {
            font-family: 'Helvetica Neue', Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 100vh;
            background: #f8f9fa;
            margin: 0;
        }

        .container {
            background: white;
            padding: 2rem;
            border-radius: 12px;
            box-shadow: 0 4px 12px rgba(0,0,0,0.1);
            width: 90%;
            max-width: 600px;
        }

        h1 {
            color: #2c3e50;
            text-align: center;
            margin-bottom: 1.5rem;
        }

        .input-group {
            margin: 1.2rem 0;
        }

        .input-group input {
            width: 100%;
            padding: 12px;
            font-size: 16px;
            border: 2px solid #ced4da;
            border-radius: 6px;
            transition: border-color 0.3s;
        }

        .input-group input:focus {
            border-color: #4dabf7;
            outline: none;
        }

        button {
            width: 100%;
            padding: 12px;
            background: #4dabf7;
            color: white;
            border: none;
            border-radius: 6px;
            cursor: pointer;
            font-size: 16px;
            transition: background 0.3s;
            margin-top: 1rem;
        }

        button:hover {
            background: #339af0;
        }

        #result {
            margin-top: 1.5rem;
            padding: 1.2rem;
            border-radius: 6px;
            background: #e7f5ff;
            border: 1px solid #4dabf7;
        }

        .result-item {
            margin: 0.8rem 0;
            padding: 0.6rem;
            background: white;
            border-radius: 4px;
            display: flex;
            justify-content: space-between;
            align-items: center;
        }

        .result-label {
            color: #495057;
            font-weight: 500;
        }

        .result-value {
            color: #1864ab;
            font-weight: bold;
            font-size: 1.1em;
        }

        .total {
            background: #d0ebff;
            border: 1px solid #74c0fc;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>R字母数量统计器</h1>
        
        <div class="input-group">
            <input type="text" id="input1" placeholder="输入第一个字符串">
        </div>
        
        <div class="input-group">
            <input type="text" id="input2" placeholder="输入第二个字符串">
        </div>

        <button onclick="countR()">开始统计</button>

        <div id="result" style="display: none;">
            <div class="result-item">
                <span class="result-label">第一个字符串中的 R 数量：</span>
                <span class="result-value" id="count1">0</span>
            </div>
            <div class="result-item">
                <span class="result-label">第二个字符串中的 R 数量：</span>
                <span class="result-value" id="count2">0</span>
            </div>
            <div class="result-item total">
                <span class="result-label">总计 R 数量：</span>
                <span class="result-value" id="total">0</span>
            </div>
        </div>
    </div>

    <script>
        function countR() {
            // 获取输入内容
            const str1 = document.getElementById('input1').value;
            const str2 = document.getElementById('input2').value;
            const resultDiv = document.getElementById('result');

            // 统计函数（不区分大小写）
            const countR = (str) => (str.match(/r/gi) || []).length;

            // 计算数量
            const count1 = countR(str1);
            const count2 = countR(str2);
            const total = count1 + count2;

            // 更新显示
            document.getElementById('count1').textContent = count1;
            document.getElementById('count2').textContent = count2;
            document.getElementById('total').textContent = total;
            resultDiv.style.display = 'block';
        }
    </script>
</body>
</html>